OHOS_SDK_HOME="$(echo "$OHOS_SDK_HOME"|awk '{  gsub(/\\/, "/");  print }')"
OHOS_SDK_HOME=$OHOS_SDK_HOME
OHOS_NATIVE_HOME=$OHOS_SDK_HOME/HarmonyOS-NEXT-DB6/openharmony/native
# echo "OHOS_SDK_HOME:"$OHOS_SDK_HOME
#OHOS_NATIVE_HOME2="$(echo "$OHOS_NATIVE_HOME"|awk '{  gsub(/ /, " ");  print }')"
OHOS_NATIVE_HOME2="D:/OHOS_NATIVE_HOME"
sysroot="$OHOS_NATIVE_HOME2/sysroot"
#ln -s "$OHOS_NATIVE_HOME/sysroot" $sysroot  # 空格原因加入，软链接
#  global-dynamic
# -ftls-model=initial-exec
# --with_tls=desc -mtls-dialect=desc
export BASE_FLAGS="--sysroot=$sysroot -pthread -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -fPIC -ftls-model=global-dynamic  -v "
# echo "BASE_FLAGS:"$BASE_FLAGS
# 保留dwarf调试符号
#GOFLAGS="-ldflags=-compressdwarf=false"

export GOOS="linux"  # 目标机器 windows
export GOARCH="arm64"  # 目标机器 amd64 arm64
#export GOBIN="/home/ender/下载/go/bin"
export GOEXE=""
export GOHOSTARCH="amd64"  # 本地机器
export GOHOSTOS="windows" # 本地机器
#export GOPATH="/home/ender/go:/home/ender/下载/goproject"
export GORACE=""
#export GOROOT="/home/ender/下载/go"
#export GOTOOLDIR="/home/ender/下载/go/pkg/tool/linux_386"
#export GCCGO="gccgo" # gcc编译的go
#export GO386=""
#export CC="gcc"
#
#export GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -gno-record-gcc-switches $BASE_FLAGS -fdebug-prefix-map=./tmp-build=./tmp-build"
#export CXX="g++"
#export CGO_ENABLED="1"
export PKG_CONFIG="pkg-config"
# -extld=$OHOS_NATIVE_HOME2/llvm/bin/ld.lld  --extldflags=-fuse-ld=$OHOS_NATIVE_HOME2/llvm/bin/ld.lld
export CGO_CFLAGS="-g -O2  $BASE_FLAGS"
export CGO_CPPFLAGS="-g -O2 -w -s -extld=$OHOS_NATIVE_HOME2/llvm/bin/ld.lld -extldflags=-fuse-ld=$OHOS_NATIVE_HOME2/llvm/bin/ld.lld  -pthread $BASE_FLAGS"
#export CGO_CXXFLAGS="-g -O2"
#export CGO_FFLAGS="-g -O2 -s -w  -pthread $BASE_FLAGS"
# -s  移除符号表和调试信息，减小生成的二进制文件的大小  -w 屏蔽警告当成错误信息？ 忽略DWARFv3调试信息，使用该选项后将无法使用gdb进行调试。（去掉-w参数之后，可在go源码（src/runtime/cgo/cgo.go）中关闭-Wall -Werror）
export CGO_LDFLAGS="-g -O2 -w -s -pthread $BASE_FLAGS "
# -ldflags


export NM=$OHOS_NATIVE_HOME/llvm/bin/llvm-nm
export AR=$OHOS_NATIVE_HOME/llvm/bin/llvm-ar
export LD=$OHOS_NATIVE_HOME/llvm/bin/ld.lld
export CXXFLAGS="--target=aarch64-linux-ohos -march=armv8a $BASE_FLAGS  -fdebug-prefix-map=C:\\Users\\admin\\AppData\\Local\\Temp\\go-build3286832040\=./tmp-build"
export CFLAGS="--target=aarch64-linux-ohos -march=armv8a $BASE_FLAGS "
#export GOARCH=arm64
#export GOOS=linux
export CGO_ENABLED=1
export CC="\"$OHOS_NATIVE_HOME/llvm/bin/clang\" $CFLAGS"
# echo "CC:"$CC
export CXX="\"$OHOS_NATIVE_HOME/llvm/bin/clang++\" $CFLAGS "
# echo "CXX:"$CXX
export RANLIB=$OHOS_NATIVE_HOME/llvm/bin/llvm-ranlib
#export GO_LDSO==$OHOS_NATIVE_HOME2/llvm/bin/ld.lld # 面向libc的musl的LLD链接器

cd .
gobin="$(where go)"
gobin="$(echo "$gobin"|awk '{  gsub(/\\/, "/");  print }')" # 路径分隔符替换
#echo $gobin
GOPATH="$(echo "$GOPATH"|awk '{  gsub(/\/\//, ":/");  print }')"
#echo $GOPATH

# 保留dwarf调试符号
#export GOFLAGS="-ldflags=-compressdwarf=false"


#    -n -a 重建 -extldflags=-fuse-ld=$OHOS_NATIVE_HOME2/llvm/bin/ld.lld -extld=$OHOS_NATIVE_HOME2/llvm/bin/clang++  -dumpdep
# third_party/hello/libs/
# pie c-shared -work打印路径并保留中间文件
# -gcflags=-S 输出源文件汇编列表
# export GOSSAFUNC=main 中间码
# -N -l 禁止内联优化， -gcflags="all=-N -l" 使得可连接调试工具
# -x 打印命令
"$gobin" build -x -v -work -tlsmodegd -buildmode=c-shared  -o ../../../libs/arm64-v8a/libhello.so  main.go

#
#"$gobin" tool compile -E -o ../../../libs/arm64-v8a/libhello.so  main.go